package com.lhn.netty.netty_demo.protocoltcp;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * 编码
 *
 * @author lhn
 * @date 2025/06/15 17:45
 * @since 1.0.0
 **/
public class MyMessageEncoder extends MessageToByteEncoder <MessageProtocol> {

    @Override
    protected void encode(ChannelHandlerContext ctx, MessageProtocol msg, ByteBuf out) throws Exception {
        System.out.println("MyMessageEncoder encode 被调用");
        out.writeInt(msg.getLength());
        out.writeBytes(msg.getContent());
    }
}